<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:rich="http://richfaces.org/rich"
      xmlns:s="http://jboss.com/products/seam/taglib">
 <body>
  <h:form>
      <a4j:include viewId="toolBar.xhtml"/>
      <table style="width:100%">
       <tr>
        <td style="width:80%"  valign="top">
          <rich:datascroller for="returnVersionsTable"/>
              <rich:dataTable id="returnVersionsTable" var="retVers" value="#{returnVersionSession.getReturnVersions()}" rows="15" style="width:100%">
                  <rich:column  style="text-align:center" sortBy="#{retVers.code}">
                      <f:facet name="header">
                          #{messages['fina2.code']}
                      </f:facet>
                      <h:outputText value="#{retVers.code}"/>
                  </rich:column>
                  <rich:column style="text-align:center" sortBy="#{retVers.description}" >
                      <f:facet name="header">
                          #{messages['fina2.description']}
                      </f:facet>
                      <h:outputText value="#{retVers.description}"/>
                  </rich:column>
                  <rich:column sortIcon="/images/edit.gif" style="text-align:center">
                      <f:facet name="header">
                          #{messages['fina2.amend']}
                      </f:facet>
                      <a4j:commandButton disabled="#{(!userSession.hasPermission('fina2.returns.version.amend'))&amp;&amp;(!roleSession.hasPermission(userSession.currentUser.id,'fina2.returns.version.amend'))}" action="#{returnVersionSession.setSelectedRetVersion(retVers)}" image="/images/edit.gif" oncomplete="Richfaces.showModalPanel('returnVersionEditPanel');" reRender="returnVersionEdit" >
                         <a4j:actionparam name="oldCode" assignTo="#{returnVersionValidator.oldCode}" value="#{retVers.code}"/>
                      </a4j:commandButton>
                  </rich:column>
                  <rich:column sortIcon="/images/remove.gif" style="text-align:center">
                      <f:facet name="header">
                          #{messages['fina2.delete']}
                      </f:facet>
                      <a4j:commandButton disabled="#{(!userSession.hasPermission('fina2.returns.version.delete'))&amp;&amp;(!roleSession.hasPermission(userSession.currentUser.id,'fina2.returns.version.delete'))}" image="/images/remove.gif" oncomplete="Richfaces.showModalPanel('confirmation')" reRender="removeRetVersion">
                          <a4j:actionparam name="retVerToRemove" assignTo="#{returnVersionSession.code}" value="#{retVers.code}"/>
                      </a4j:commandButton>
                  </rich:column>
              </rich:dataTable>
        </td>
       </tr>
      </table>
  </h:form>
  <rich:modalPanel id="confirmation" autosized="true" resizeable="false" width="300">
      <f:facet name="header">
          #{messages['fina2.delete']}
      </f:facet>
      <f:facet name="controls">
          <h:graphicImage value="/images/close.gif" onclick="Richfaces.hideModalPanel('confirmation')"/>
      </f:facet>
      <h:form>
          <s:div id="removeRetVersion">
              <table align="center" width="100%" style="font-size:12px">
                  <tr>
                     <td style="font-size:12px">#{messages['fina2.returns.returnVersionDeleteQuestion']}</td>
                  </tr>
              </table>
          </s:div>
          <rich:spacer height="5px"/>
          <table align="center">
              <tr>
                  <td>
                      <a4j:commandButton action="#{returnVersionSession.removeReturnVersion}" value="#{messages['fina2.web.ok']}" style="width:80px" oncomplete="Richfaces.hideModalPanel('confirmation')" reRender="returnVersionsTable"/>
                  </td>
                  <td><rich:spacer width="3px"/></td>
                  <td>
                      <a4j:commandButton ajaxSingle="true" onclick="Richfaces.hideModalPanel('confirmation')" value="#{messages['fina2.web.cancel']}" style="width:80px"/>
                  </td>
             </tr>
        </table>
      </h:form>
  </rich:modalPanel>
  
  <rich:modalPanel id="returnVersionPanel" autosized="true" resizeable="false" width="470">
      <f:facet name="header">
          #{messages['fina2.returns.returnVersionsAction']}
      </f:facet>
      <f:facet name="controls">
          <h:graphicImage value="/images/close.gif" onclick="Richfaces.hideModalPanel('returnVersionPanel')"/>
      </f:facet>
      
      <h:form>
          <f:facet name="beforeInvalidField">
                  <s:message style="color:red;font-size:12px"/>
              </f:facet>
              <f:facet name="aroundInvalidField">
              
              </f:facet>
              <f:facet name="afterInvalidField">
                  <s:div style="display:block;padding-bottom:12px"/>
          </f:facet>
          
          <s:div id="returnVersions">
              <table align="center" width="100%" style="font-size:12px">
                  <tr>
                      <td><rich:spacer width="12px" height="12px"/></td>
                  </tr>
                  <tr>
                      <td>#{messages['fina2.code']}</td>
                      <td><div style="color:red">*</div></td>
                      <td>
                          <s:decorate>
                              <h:inputText value="#{returnVersionSession.retVersion.code}" validator="#{returnVersionValidator.validateCode}" required="true" requiredMessage="#{messages['fina2.bank.pleaseEnterCode']}" style="width:330px"/>
                          </s:decorate>
                      </td>
                  </tr>
                   <tr>
                       <td><rich:spacer width="12px" height="12px"/></td>
                   </tr>
                    <tr>
                        <td>#{messages['fina2.description']}</td>
                        <td><div style="color:red">*</div></td>
                        <td>
                            <s:decorate> 
                                <h:inputText value="#{returnVersionSession.retVersion.description}" validator="#{returnVersionValidator.validateDescription}" required="true" requiredMessage="#{messages['fina2.pleaseEnterDescription']}"  style="width:330px"/>
                            </s:decorate>
                        </td>
                    </tr>
                </table>
                <rich:spacer height="3px"/>
                <table align="center" >
                   <tr>
                       <td><a4j:commandButton reRender="returnVersions"  action="#{returnVersionSession.addReturnVersion()}" value="#{messages['fina2.web.ok']}" style="width:80px"/></td>
                       <td><rich:spacer width="3px"/></td>
                       <td><a4j:commandButton onclick="Richfaces.hideModalPanel('returnVersionPanel');return false;" value="#{messages['fina2.cancel']}" style="width:80px"/></td>
                   </tr>
                </table>
          </s:div>
      </h:form>
  </rich:modalPanel>
  
  <rich:modalPanel id="returnVersionEditPanel" autosized="true" resizeable="false"  width="470">
      <f:facet name="header">
          #{messages['fina2.amend']}
      </f:facet>
      <f:facet name="controls">
          <h:graphicImage value="/images/close.gif" onclick="Richfaces.hideModalPanel('returnVersionEditPanel')"/>
      </f:facet>
      <h:form>
        <s:validateAll>
          <f:facet name="beforeInvalidField">
              <s:message style="color:red;font-size:12px"/>
          </f:facet>
          <f:facet name="aroundInvalidField">
          
          </f:facet>
          <f:facet name="afterInvalidField">
              <s:div style="display:block;padding-top:12px"/>
          </f:facet>
          <s:div id="returnVersionEdit">
          
              <table align="center" width="100%" style="font-size:12px">
                  <tr>
                      <td><rich:spacer width="12px" height="12px"/></td>
                  </tr>
                  <tr>
                      <td>#{messages['fina2.code']}</td>
                      <td><div style="color:red">*</div></td>
                      <td>
                          <s:decorate>
                              <h:inputText value="#{returnVersionSession.selectedRetVersion.code}" validator="#{returnVersionValidator.validateEditCode}" required="true" requiredMessage="#{messages['fina2.bank.pleaseEnterCode']}" style="width:330px"/>
                          </s:decorate>
                      </td>
                      
                  </tr>
                   <tr>
                       <td><rich:spacer width="12px" height="12px"/></td>
                   </tr>
                    <tr>
                        <td>#{messages['fina2.description']}</td>
                        <td><div style="color:red">*</div></td>
                        <td>
                                <s:decorate> 
                                    <h:inputText value="#{returnVersionSession.selectedDesc}" validator="#{returnVersionValidator.validateDescription}" required="true" requiredMessage="#{messages['fina2.pleaseEnterDescription']}"  style="width:330px">
                                    </h:inputText>
                                </s:decorate>
                        </td>
                        
                    </tr>
                </table>
                <rich:spacer height="3px"/>
                <table align="center" >
                   <tr>
                       <td><a4j:commandButton reRender="returnVersionEdit" data="#{returnVersionSession.success}" action="#{returnVersionSession.updateReturnVersion()}" value="#{messages['fina2.web.ok']}" style="width:80px" oncomplete="if(data)Richfaces.hideModalPanel('returnVersionEditPanel');"/></td>
                       <td><rich:spacer width="3px"/></td>
                       <td><a4j:commandButton onclick="Richfaces.hideModalPanel('returnVersionEditPanel');return false;" value="#{messages['fina2.cancel']}" style="width:80px" /></td>
                   </tr>
                </table>
          </s:div>
          </s:validateAll>
      </h:form>
  </rich:modalPanel>
 </body>
</html>